package com.netease.financial.base.web;

import com.netease.financial.common.util.preferences.PreferencesHelper;

/**
 * Created by wyf on 10/10/15.
 */
public class WebStoragePreferencesHelper {
    public static final String KEY_LOCAL_STORAGE_ACCESS_TOKEN = "accessToken";
    public static final String KEY_LOCAL_STORAGE_USER_ID = "userId";
    public static final String KEY_LOCAL_STORAGE_CLIENT_ID = "clientId";
    public static final String KEY_LOCAL_STORAGE_HEAD_PORTRAIT_URL = "clientImg";

    public static final String KEY_SESSION_STORAGE_HISTORIES = "historyUrl";

    public static final String KEY_USER_NEED_LOGOUT = "user_need_logout";

    private static final String PREFERENCES_FILE_NAME = PreferencesHelper.getFullPreferenceFileName("local_storage");

    private static PreferencesHelper sPreferencesHelper;

    private static PreferencesHelper getPreferencesHelper() {
        if (sPreferencesHelper == null) {
            sPreferencesHelper = PreferencesHelper.newInstance(PREFERENCES_FILE_NAME);
        }
        return sPreferencesHelper;
    }

    public static void saveLocalStorageItem(String itemName, String itemValue) {
        getPreferencesHelper().putString(itemName, itemValue);
    }

    public static String getLocalStorageItem(String itemName) {
        return getPreferencesHelper().getString(itemName, "");
    }

    public static void setUserNeedLogout(boolean need) {
        getPreferencesHelper().putBoolean(KEY_USER_NEED_LOGOUT, need);
    }

    public static boolean isUserNeedLogout() {
        return getPreferencesHelper().getBoolean(KEY_USER_NEED_LOGOUT, false);
    }

}
